package com.terrace.core.mybatis.plugin.pagination.sqlsource;

import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.scripting.defaults.RawSqlSource;

/**
 * 
 * @author jiangyg
 *
 */
public class CustomRawSqlSource extends PaginationSqlSource {
	
    private PaginationSqlSource sqlSource;

	public CustomRawSqlSource(RawSqlSource sqlSource) {
        MetaObject metaObject = SystemMetaObject.forObject(sqlSource);
        this.sqlSource = new CustomStaticSqlSource((StaticSqlSource) metaObject.getValue("sqlSource"));
    }
	
	@Override
    protected BoundSql getDefaultBoundSql(Object parameterObject) {
        return sqlSource.getDefaultBoundSql(parameterObject);
    }

    @Override
    protected BoundSql getCountBoundSql(Object parameterObject) {
        return sqlSource.getCountBoundSql(parameterObject);
    }

	@Override
	protected BoundSql getPaginationBoundSql(Object parameterObject) {
		 return sqlSource.getPaginationBoundSql(parameterObject);
	}

}